package com.hmall.search.pojo;

import com.hmall.common.dto.Item;
import com.hmall.common.dto.ItemDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ItemDOC {
    private Long id;//商品id
    private String name;//商品名称
    private Long price;//价格（分）
    private Integer stock;//库存数量
    private String image;//商品图片
    private String category;//分类名称
    private String brand;//品牌名称
    private Integer sold;//销量
    private Integer commentCount;//评论数
    private Boolean isAD;// 是否是广告
    private List<String> suggestion;//自动补全字段
    
    public ItemDOC(Item item) {
        this.id = item.getId();
        this.name = item.getName();
        this.price = item.getPrice();
        this.stock = item.getStock();
        this.image = item.getImage();
        this.category = item.getCategory();
        this.brand = item.getBrand();
        this.sold = item.getSold();
        this.commentCount = item.getCommentCount();
        this.isAD = item.getIsAD();
        suggestion = new ArrayList<String>();
        if (StringUtils.isNotEmpty(this.brand)){
            this.suggestion.add(this.brand);
        }
        if (StringUtils.isNotEmpty(this.category)){
            this.suggestion.add(this.category);
        }
    }
}
